import { configureStore } from '@reduxjs/toolkit';

interface IStore {
  [key: string]: any;
}

const requireModules = require.context("./slices", false, /.ts$/);
const reducer = requireModules.keys().reduce((modules: IStore, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
  modules[moduleName] = requireModules(modulePath).default;
  return modules;
}, {});

// 创建 Store
const store = configureStore({
  reducer: {
    // 定义 Reducers
    ...reducer
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      // 可选配置，例如禁用序列化检查
      serializableCheck: false,
    }),
});

export default store;